<template>
    <div>
<!--        <el-button @click="querySellList">查询</el-button>-->
        <el-button type="danger" icon="el-icon-delete" circle @click="closeTable"></el-button>
        <el-button @click="closeStartTime">隐藏开售时间</el-button>
        <el-button @click="closeEndTime">隐藏结售时间</el-button>
        <el-button @click="closeRole">隐藏角色</el-button>
        <template >
            <el-table
                    :data="tableData"
                    stripe
                    style="width: 100%">
                <el-table-column
                        prop="info"
                        label="外观名称"
                        width="180">
                </el-table-column>
                <el-table-column
                        prop="price"
                        label="价格"
                        width="180">
                </el-table-column>

                <el-table-column
                        prop="server_name"
                        label="区服">
                </el-table-column>
                <el-table-column
                        v-if="showRole"

                        prop="role_name"
                        label="角色">
                </el-table-column>
                <el-table-column
                        v-if="showStartTime"
                        prop="startTime"
                        label="开售时间"
                        width="180"
                >
                </el-table-column>

                <el-table-column
                        v-if="showEndTime"
                        prop="endTime"
                        label="结售时间"
                        width="180"
                >
                </el-table-column>
<!--                <el-table-column-->
<!--                        fixed="right"-->
<!--                        label="操作"-->
<!--                        width="100">-->
<!--                    <template slot-scope="scope">-->
<!--&lt;!&ndash;                        <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>&ndash;&gt;-->
<!--                        <el-button type="text" size="small"  @click="handleClick(scope.row)">编辑</el-button>-->
<!--                    </template>-->
<!--                </el-table-column>-->
            </el-table>
        </template>
    </div>
</template>

<script>
    import client from "./request/axios-request";
    export default {
        name: "SellList",
        mounted() {
            this.querySellList();
        },

        data() {
            return {
                callback:'__xfe1',
                req_id:'',
                tableData: [],
                showTable:true,
                showStartTime: true,
                showEndTime: true,
                showRole: true
            }
        },
        methods:{
            closeStartTime(){
                this.showStartTime = !this.showStartTime;
            },
            closeEndTime(){
                this.showEndTime = !this.showEndTime;
            },
            closeRole(){
                this.showRole = !this.showRole;
            },
            querySellList(){
                this.showTable = true;
                const url =
                    `https://trade-api.seasunwbl.com/api/seller/goods/consignment_list?req_id=11111&game_id=jx3&goods_type=3&__ts__=1723787047529&callback=${this.callback}`;

                console.log('11111');
                client.request(url)
                    .then((res)=>{
                        console.log("succcc");
                        // console.log(typeof (res.data));
                        const sellListStr = res.data.substring(this.callback.length+1,res.data.length - 2);
                        // console.log( sellListStr);
                        const sellList = JSON.parse(sellListStr);
                        console.log(sellList.data.list);
                        this.tableData = this.formatDataList(sellList.data.list);

                    })
                    .catch((err)=>{
                        console.log("errr");
                        console.log(err)
                    })
            },
            formatDataList(rawData){
                const newList = [];
                for (let i = 0; i < rawData.length; i++){
                    let  tempObj = {};
                    const {info, single_unit_price, remaining_time,server_name,role_name, state, consignment_id} = rawData[i];
                    const sellTime =parseInt(Date.now() + remaining_time*1000) ;
                    const remainingTime =  new Date(sellTime).toLocaleString().replace(/:\d{1,2}$/,'');
                    const price = single_unit_price/100;
                    tempObj =  {info, price, server_name, role_name, consignment_id};
                    if (state === 3){//公示
                        tempObj["startTime"]= remainingTime;
                        tempObj["endTime"] = "-"
                    }
                    if (state === 5){//在售
                        tempObj["endTime"]= remainingTime;
                        tempObj["startTime"] = "-"
                    }

                    newList.push(tempObj);
                }
                console.log(newList);
                return newList;
            },
            handleClick(data){
                console.log(data);
                const urlChangePrice = `https://trade-api.seasunwbl.com/api/seller/goods/consignment_update_price?req_id=WG4bhM4k9UqRexmib112JXvCmRpgpf7h&game_id=jx3&single_unit_price=155100&goods_type=3&validate_type=2&consignment_id=${data.consignment_id}&second_password=c2ff872adce77b63db57c9ed2c5e59f2348f7363&__ts__=1723823193135&callback=__xfe13`;
                console.log(urlChangePrice);
                client.request(urlChangePrice)
                .then((res)=>{
                    console.log('changePriceSuc',res);
                })
                .catch((err)=>{
                    console.log('urlChangePrice',err);
                })
                },

            closeTable(){
                this.$emit("close");
            }
        }
    }
</script>

<style scoped>

</style>